<!-- @author Shiyn/   huangmx 20200807优化-->
<template>
  <div class="top-right-btn">
    <el-row>
      <vxe-checkbox v-model="autoRefresh" @change="handleAutoRefresh">自动刷新</vxe-checkbox>
      <el-tooltip class="item" effect="dark" :content="showSearch ? '隐藏搜索' : '显示搜索'" placement="top">
        <el-button size="mini" circle icon="el-icon-search" @click="toggleSearch()" />
      </el-tooltip>
      <el-tooltip class="item" effect="dark" content="刷新" placement="top">
        <el-button size="mini" circle icon="el-icon-refresh" @click="refresh()" />
      </el-tooltip>
    </el-row>
  </div>
</template>
<script>
export default {
  name: "RightToolbar",
  data() {
    return {
      autoRefresh: false,
      clock: null
    };
  },
  props: {
    showSearch: {
      type: Boolean,
      default: true,
    },
  },
  methods: {
    //搜索
    toggleSearch() {
      this.$emit("update:showSearch", !this.showSearch);
    },
    //刷新
    refresh() {
      this.$emit("queryTable");
    },
    //自动刷新
    handleAutoRefresh(_) {
      let that = this
      if (this.autoRefresh) {
        if (this.clock != null) {
          clearInterval(this.clock)
          this.clock = null
        }
        this.clock = setInterval(function() {
          that.$emit("queryTable", true)
        }, 1000)
      } else {
        clearInterval(this.clock)
        this.clock = null
      }
    }
  },
};
</script>
